package org.NooLab.openNLP.sources;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

import org.NooLab.openNLP.grammar.ArgumentsObject;
import org.NooLab.openNLP.grammar.HarvestersInitIntf;
import org.NooLab.utilities.files.DFutils;
import org.NooLab.utilities.logging.PrintLog;

 

/**
 * 
 * 
 */
public class LextHarvesterFactory {

	// =================================
	
	// object references ..............

	LextHarvesterIntf lextHarvesterIntf;
	ArgumentsObject arguments = new ArgumentsObject() ;
	
	
	// main variables / properties ....

	HarvestersInitIntf pointOfInit;
	String language="", resourceAddr="" ;
	
	String nlpDataPath;
	
	
	// constants ......................

	// volatile variables .............

	
	// helper objects .................
	PrintLog out;
	
	// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
	public LextHarvesterFactory(){
		
	}
	
	// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
	public LextHarvesterIntf getLexThesaurusHarvester( String lang, 
			 										   String nlpdatapath , 
			 										   PrintLog outprn ){

		LextHarvesterIntf  cjh = null ; 


         language = lang;
         nlpDataPath = nlpdatapath ;


         out = outprn ;

 
         cjh = pointOfInit.initLextHarvester(resourceAddr) ;

         
 
         lextHarvesterIntf = cjh;
         return cjh;
	} 

	@SuppressWarnings("unchecked")
	public LextHarvesterIntf getInstanceofHarvester( Class  harvesterClass, Object[] intArgs) {

		LextHarvesterIntf cjh = null;

		Constructor<?> intArgsConstructor;

		try {

			arguments.setIntArgs(intArgs);

			intArgsConstructor = harvesterClass.getConstructor(arguments.getIntArgsClass());

			cjh = (LextHarvesterIntf) createObject(intArgsConstructor, arguments.getIntArgs());

		} catch (NoSuchMethodException e) {
			System.out.println(e);
		}



		return cjh;
	}

	private Object createObject(Constructor<?> constructor, Object[] arguments) {

		 
		Object object = null;

		try {

			object = constructor.newInstance(arguments);
 
			return object;

		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}

		return object;
	}

	public void setCallbackPoint( HarvestersInitIntf pointofinit ){
		
		pointOfInit = pointofinit ;
	}
	
	public void setResourceAddr(String resourceAddr) {
		this.resourceAddr = resourceAddr;
	}


	public ArgumentsObject getArgumentsObject() {
		return arguments;
	}


	public void setArguments(ArgumentsObject arguments) {
		this.arguments = arguments;
	}

}
